package com.example.androidpattern.factory;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.example.androidpattern.AppConstant;
import com.example.androidpattern.EMTagHandler;
import com.example.androidpattern.R;
import com.example.androidpattern.factory.method.BeiJingFactory;
import com.example.androidpattern.factory.method.XiAnFactory;
import com.example.androidpattern.factory.simple.IRouJiaMo;
import com.example.androidpattern.factory.simple.SimpleFactory;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class FactoryActivity extends AppCompatActivity {

    @BindView(R.id.btn_factory_simple)
    Button btnFactorySimple;
    @BindView(R.id.btn_factory_method)
    Button btnFactoryMethod;
    @BindView(R.id.btn_factory_abstract)
    Button btnFactoryAbstract;
    @BindView(R.id.tv_factory_simple_info)
    TextView tvFactorySimpleInfo;
    @BindView(R.id.tv_factory_method_info)
    TextView tvFactoryMethodInfo;
    @BindView(R.id.tv_factory_abstract_info)
    TextView tvFactoryAbstractInfo;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_factory);
        ButterKnife.bind(this);
        tvFactorySimpleInfo.setText(EMTagHandler.fromHtml(AppConstant.JDGC_FACTORY_DEFINE));
        tvFactoryMethodInfo.setText(EMTagHandler.fromHtml(AppConstant.GCFF_FACTORY_DEFINE));
        tvFactoryAbstractInfo.setText(EMTagHandler.fromHtml(AppConstant.CXGC_FACTORY_DEFINE));
    }

    @OnClick({R.id.btn_factory_simple, R.id.btn_factory_method, R.id.btn_factory_abstract})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_factory_simple:
                simpleFactory();
                break;

            case R.id.btn_factory_method:
                methodFactory();
                break;

            case R.id.btn_factory_abstract:
                break;
        }
    }

    private void methodFactory() {
        BeiJingFactory beiJingFactory = new BeiJingFactory();
        XiAnFactory xiAnFactory = new XiAnFactory();

        com.example.androidpattern.factory.method.IRouJiaMo rouJiaMoBeiJingA = beiJingFactory.makeRouJiaMo("A");
        com.example.androidpattern.factory.method.IRouJiaMo rouJiaMoBeiJingB = beiJingFactory.makeRouJiaMo("B");
        com.example.androidpattern.factory.method.IRouJiaMo rouJiaMoXiAnA = xiAnFactory.makeRouJiaMo("A");

        rouJiaMoBeiJingA.make();
        rouJiaMoBeiJingB.make();
        rouJiaMoXiAnA.make();
    }

    private void simpleFactory() {
        SimpleFactory simpleFactory = new SimpleFactory();
        IRouJiaMo rouJiaMoA = simpleFactory.makeRouJiaMo("A");
        rouJiaMoA.make();
        IRouJiaMo rouJiaMoB = simpleFactory.makeRouJiaMo("B");
        rouJiaMoB.make();
    }
}